local skel = fk.CreateSkill {
  name = "emo__modian",
}

Fk:loadTranslationTable{
  ["emo__modian"] = "魔典",
  [":emo__modian"] = "出牌阶段，你可以弃置一张手牌，本回合你于不能弃置此花色的手牌且这些牌不计入手牌上限，然后你可以使用一个随机恶魔技能。",

  ["@emo__modian-turn"] = "魔典",
  ["#emo__modian-choice"] = "魔典:选择使用一个恶魔技能",
  ["#emo__modian-prompt"] = "魔典:弃置一张手牌，使用一个随机恶魔技能",
}

skel:addEffect("active", {
  anim_type = "control",
  card_num = 1,
  target_num = 0,
  prompt = "#emo__modian-prompt",
  card_filter  =function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).suit ~= Card.NoSuit and table.contains(player.player_cards[Player.Hand], to_select)
    and not player:prohibitDiscard(Fk:getCardById(to_select))
  end,
  can_use = function(self, player)
    return table.find(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).suit ~= Card.NoSuit and not player:prohibitDiscard(id)
    end)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local suit = Fk:getCardById(effect.cards[1]):getSuitString(true)
    room:throwCard(effect.cards, self.name, player, player)
    if not player.dead then
      room:addTableMarkIfNeed(player, "@emo__modian-turn", suit)
    end
    if player.dead then return end
    local demon_skills = {"emo__aoman","emo__fennu","emo__baoshi","emo__jidu","emo__landuo","emo__tanlan","emo__seyu"}
    local skills = table.filter(demon_skills, function (name)
      local s = Fk.skills[name]
      return s and s:isInstanceOf(ActiveSkill) and s:canUse(player)
    end)
    if #skills == 0 then return end
    local choice = room:askToChoice(player, { choices =  table.random(skills, 2), skill_name = self.name,
    prompt = "#emo__modian-choice", detailed = true})
    local success, dat = room:askToUseActiveSkill(player, { skill_name = choice, skip = true })
    if success and dat then
      player:addSkillUseHistory(choice, 1)
      room:notifySkillInvoked(player, choice)
      local skill = Fk.skills[choice] ---@type ActiveSkill
      skill:onUse(room, SkillUseData:new {cards = dat.cards, tos = dat.targets, from = player })
    end
  end,
})

skel:addEffect("prohibit", {
  prohibit_discard = function (self, player, card)
    return card and table.contains(player.player_cards[Player.Hand], card.id)
    and table.contains(player:getTableMark("@emo__modian-turn"), card:getSuitString(true))
  end,
})

skel:addEffect("maxcards", {
  exclude_from = function(self, player, card)
    return card and table.contains(player:getTableMark("@emo__modian-turn"), card:getSuitString(true))
  end,
})

return skel
